package com.joven.product.api.business.client;

import com.joven.product.api.business.client.model.User;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户客户端
 *
 * @author Joven
 * @date 2022/6/30 09:35
 */
@Component
public class UserClient {
    public User getById(Long id) {
        if (id.equals(1L)) {
            return new User(1L, "Joven");
        }
        return null;
    }

    public List<User> listByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.emptyList();
        }
        List<User> users = new ArrayList<>();
        users.add(new User(1L, "Joven"));
        users.add(new User(2L, "zhan"));
        return users.stream().filter(user -> ids.contains(user.getId())).collect(Collectors.toList());
    }
}